/**
 \* Created with IntelliJ IDEA.
 \* @author: walter_long
 \* @time: 2018/11/15 12:01
 \* Description: 用户state，用于存放用户相关数据（用户、权限组、菜单）
 \*/
import API from "../../api/api_user";

const state = {
    /**
     * UserSelect的临时数据存储
     */
    userSelect: {
        selectIds: []
    }
};

const getters = {
    userSelect: state => {
        return state.userSelect;
    }
};

/**
 * 登录后，将后台发送权限数据进行格式化处理
 * @param userData
 */
function formatCUserPermissions(userData) {
    let user = JSON.parse(userData);
    user.roleVo.permissionGroup.forEach(menu => {
        menu.permission = menu.permission.map(buttonPermission => {
            return buttonPermission.value;
        })
    });
    return user;
}

const actions = {
    setUserSelectAct({state, commit}, params) {
        commit("setUserSelect", params);
    }
};

const mutations = {
    setUserSelect(state, entity) {
        state.userSelect = entity
    },
};

export default {
    state,
    getters,
    actions,
    mutations,
    namespaced: true
}
